const wx2my = require('../../wx2my');

// pages/report/report.js
const app = getApp();
let page = 1;
let totalpage;
Page({
  data: {
    keyword: ''
  },
  onLoad: function (e) {},
  onReady: function () {},
  onShow: function () {
    page = 1;
    this.get_list();
  },

  get_list() {
    let that = this;
    app.wxRequest('feedback_list', {
      'shop_token': wx2my.getStorageSync('shop_token'),
      'page': page,
      'keyword': that.data.keyword
    }, function (res) {
      console.log(res);

      if (res.data.code == 1) {
        let list = res.data.data.list;

        if (page == 1) {
          totalpage = res.data.data.totalpage;
        }

        that.setData({
          list: page == 1 ? list : that.data.list.concat(list),
          lock: totalpage <= page ? true : false
        });
      }
    });
  },

  searchInput(e) {
    console.log(e);
    this.setData({
      keyword: e.detail.value
    });

    if (e.detail.value == '') {
      page = 1;
      this.get_list();
    }
  },

  search() {
    let that = this;

    if (that.data.keyword == '') {
      app.toast('请输入设备编号或地址！');
    } else {
      page = 1;
      that.get_list();
    }
  },

  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {
    page++;

    if (!this.data.lock) {
      this.get_list();
    }
  },
  previewImage: function (e) {
    console.log(e.target.dataset.src);
    var list = e.currentTarget.dataset.seclist;
    wx2my.previewImage({
      current: e.target.dataset.src,
      // 当前显示图片的http链接
      urls: list,
      // 需要预览的图片http链接列表
      success: function (res) {
        console.log(res);
      }
    });
  },
  onShareAppMessage: function () {}
});